package com.tyk.bookstore.front.product.model.enume;

import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.fasterxml.jackson.annotation.JsonValue;
import com.tyk.bookstore.front.common.core.model.enume.BaseEnum;
import com.tyk.bookstore.front.product.model.entity.BookStatisticDo;

public enum BookSortOrder implements BaseEnum {
    MULTIPLE(1),
    SALE_NUM(2),
    PRICE(3),
    COMMENT_NUM(4);

    @JsonValue
    private final Integer code;

    @Override
    public Integer value() {
        return this.code;
    }

    BookSortOrder(Integer code) {
        this.code = code;
    }


    /**
     * 书籍排序字段枚举转 BookStatisticDo属性Lambda表达式
     */
    public SFunction<BookStatisticDo, ?> toField() {
        return switch (this) {
            case MULTIPLE, SALE_NUM -> BookStatisticDo::getSaleNum;
            case PRICE -> BookStatisticDo::getPrice;
            case COMMENT_NUM -> BookStatisticDo::getCommentNum;
        };
    }
}
